package game.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import common.controller.base.BaseController;
import common.model.po.*;
import common.model.response.base.Result;
import game.model.request.*;
import game.service.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 类别管理
 *
 * @author 米泽鹏
 * @since 2022-02-26
 */
@Api(tags = "类别管理")
@RestController
@RequestMapping("/game/g-classification")
public class GClassificationController extends BaseController {

	@Resource
	private GClassificationService service;
	@Resource
	private GBuildingService buildingService;
	@Resource
	private GItemService itemService;
	@Resource
	private GCreatureService creatureService;
	@Resource
	private GProductService productService;
	@Resource
	private GBlueprintService blueprintService;

	@ApiOperation(value = "获取类别树", notes = "获取类别树")
	@PostMapping("/readOnly/getClassificationTree")
	public Result<?> getClassificationTree(@ApiParam(value = "获取类别树请求", required = true) @RequestBody @Validated GetClassificationTreeRequest request) {
		return successWithData(service.getClassificationTree(request.getType()));
	}

	@ApiOperation(value = "类别保存", notes = "类别保存")
	@PostMapping("/saveClassification")
	public Result<?> saveClassification(@ApiParam(value = "类别保存请求列表", required = true) @RequestBody @Validated SaveClassificationRequest request) {
		return service.saveClassification(request);
	}

	@ApiOperation(value = "获取所有建筑", notes = "获取所有建筑")
	@PostMapping("/readOnly/getAllBuilding")
	public Result<?> getAllBuilding() {
		List<GBuilding> buildingList = buildingService.list(new LambdaQueryWrapper<GBuilding>().select(GBuilding::getId, GBuilding::getBuildingName, GBuilding::getImage));
		return successWithData(buildingList);
	}

	@ApiOperation(value = "获取所有物品", notes = "获取所有物品")
	@PostMapping("/readOnly/getAllItem")
	public Result<?> getAllItem() {
		List<GItem> itemList = itemService.lambdaQuery().select(GItem::getId, GItem::getItemName, GItem::getImage).list();
		return successWithData(itemList);
	}

	@ApiOperation(value = "获取所有生物", notes = "获取所有生物")
	@PostMapping("/readOnly/getAllCreature")
	public Result<?> getAllCreature() {
		List<GCreature> creatureList = creatureService.lambdaQuery().select(GCreature::getId, GCreature::getCreatureName, GCreature::getImage).list();
		return successWithData(creatureList);
	}

	@ApiOperation(value = "获取所有商品", notes = "获取所有商品")
	@PostMapping("/readOnly/getAllProduct")
	public Result<?> getAllProduct() {
		List<GProduct> productList = productService.lambdaQuery().select(GProduct::getId, GProduct::getProductName, GProduct::getImage).list();
		return successWithData(productList);
	}

	@ApiOperation(value = "获取所有蓝图", notes = "获取所有蓝图")
	@PostMapping("/readOnly/getAllBlueprint")
	public Result<?> getAllBlueprint() {
		List<GBlueprint> blueprintList = blueprintService.lambdaQuery().select(GBlueprint::getId, GBlueprint::getBlueprintName, GBlueprint::getImages).list();
		return successWithData(blueprintList);
	}

	@ApiOperation(value = "类别分配建筑保存", notes = "类别分配建筑保存")
	@PostMapping("/saveClassificationBuilding")
	public Result<String> saveClassificationBuilding(@ApiParam(value = "类别分配建筑保存请求", required = true) @RequestBody @Validated SaveClassificationBuildingRequest request) {
		return service.saveClassificationBuilding(request);
	}

	@ApiOperation(value = "类别分配物品保存", notes = "类别分配物品保存")
	@PostMapping("/saveClassificationItem")
	public Result<String> saveClassificationItem(@ApiParam(value = "类别分配物品保存请求", required = true) @RequestBody @Validated SaveClassificationItemRequest request) {
		return service.saveClassificationItem(request);
	}

	@ApiOperation(value = "类别分配生物保存", notes = "类别分配生物保存")
	@PostMapping("/saveClassificationCreature")
	public Result<String> saveClassificationCreature(@ApiParam(value = "类别分配生物保存请求", required = true) @RequestBody @Validated SaveClassificationCreatureRequest request) {
		return service.saveClassificationCreature(request);
	}

	@ApiOperation(value = "类别分配商品保存", notes = "类别分配商品保存")
	@PostMapping("/saveClassificationProduct")
	public Result<String> saveClassificationProduct(@ApiParam(value = "类别分配商品保存请求", required = true) @RequestBody @Validated SaveClassificationProductRequest request) {
		return service.saveClassificationProduct(request);
	}

	@ApiOperation(value = "类别分配蓝图保存", notes = "类别分配蓝图保存")
	@PostMapping("/saveClassificationBlueprint")
	public Result<String> saveClassificationBlueprint(@ApiParam(value = "类别分配蓝图保存请求", required = true) @RequestBody @Validated SaveClassificationBlueprintRequest request) {
		return service.saveClassificationBlueprint(request);
	}

	@ApiOperation(value = "查询一个类别下的建筑", notes = "查询一个类别下的建筑")
	@GetMapping("/readOnly/getAllBuildingByClassId/{classId}")
	public Result<?> getAllBuildingByClassId(@ApiParam(value = "类别id", required = true) @PathVariable Long classId) {
		List<GBuilding> buildingList = buildingService.lambdaQuery().eq(GBuilding::getClassificationId, classId).select(GBuilding::getId).orderByAsc(GBuilding::getSort).list();
		return successWithData(buildingList);
	}

	@ApiOperation(value = "查询一个类别下的物品", notes = "查询一个类别下的物品")
	@GetMapping("/readOnly/getAllItemByClassId/{classId}")
	public Result<?> getAllItemByClassId(@ApiParam(value = "类别id", required = true) @PathVariable Long classId) {
		List<GItem> itemList = itemService.lambdaQuery().eq(GItem::getClassificationId, classId).select(GItem::getId).orderByAsc(GItem::getSort).list();
		return successWithData(itemList);
	}

	@ApiOperation(value = "查询一个类别下的生物", notes = "查询一个类别下的生物")
	@GetMapping("/readOnly/getAllCreatureByClassId/{classId}")
	public Result<?> getAllCreatureByClassId(@ApiParam(value = "类别id", required = true) @PathVariable Long classId) {
		List<GCreature> creatureList = creatureService.lambdaQuery().eq(GCreature::getClassificationId, classId).select(GCreature::getId).orderByAsc(GCreature::getSort).list();
		return successWithData(creatureList);
	}

	@ApiOperation(value = "查询一个类别下的商品", notes = "查询一个类别下的商品")
	@GetMapping("/readOnly/getAllProductByClassId/{classId}")
	public Result<?> getAllProductByClassId(@ApiParam(value = "类别id", required = true) @PathVariable Long classId) {
		List<GProduct> productList = productService.lambdaQuery().eq(GProduct::getClassificationId, classId).select(GProduct::getId).orderByAsc(GProduct::getSort).list();
		return successWithData(productList);
	}

	@ApiOperation(value = "查询一个类别下的蓝图", notes = "查询一个类别下的蓝图")
	@GetMapping("/readOnly/getAllBlueprintByClassId/{classId}")
	public Result<?> getAllBlueprintByClassId(@ApiParam(value = "类别id", required = true) @PathVariable Long classId) {
		return successWithData(service.getAllBlueprintByClassId(classId));
	}

}
